<?php

App::uses('AppModel', 'Model');
App::uses('CompositeKeyModel', 'Model');

/**
 * Member Model
 *
 * @property Organisation $Organisation
 * @property MemberBiodata $MemberBiodata
 * @property MemberChild $MemberChild
 * @property OrganisationMemberContribution $OrganisationMemberContribution
 * @property OrganisationMemberAnniversary $OrganisationMemberAnniversary
 * @property OrganisationMemberGroup $OrganisationMemberGroup
 * @property MemberParent $MemberParent
 * @property MemberSpouse $MemberSpouse
 */
class Country extends CompositeKeyModel {
    
    public $useDbConfig = "organisations";

    //The Associations below have been created with all possible keys, those that are not needed can be removed
    
    /**
     * belongsTo associations
     *
     * @var array
     */
    public $hasOne = array(
        'Currency' => array(
            'className' => 'Currency',
            'foreignKey' => 'country_id',
            'conditions' => '',
            'fields' => '',
            'order' => 'Country.name asc'
        )
    );


    public function getCountries() {
        return $this->find('all', array(
            'conditions' => array(
                'Country.active' => 1
            ),
            'recursive'=>-1
        ));
    }
    
    public function getCountry($country_id) {
        return $this->find('first', array(
            'conditions' => array(
                'Country.id' => $country_id,
                'Country.active' => 1
            ),
            'contain'=>array(
                'Currency'=>array('fields'=>array('Currency.id','Currency.currency_name','Currency.currency_code'))
            ),
            'recursive'=>1
        ));
    }
    
    
    
    /**
     * Flags the specified member as deleted in the organisation
     * 
     * @param type $organisation_id
     * @param type $member_id
     * @return type
     */
    public function deleteCountry($country_id) {
        return $this->save(array(
            'id' => $country_id,
            'active' => 0
        ));
    }
}
